// Qt on Metro test application
// Copyright (c) Andrew Knight
// This software is licensed under the MIT: http://www.opensource.org/licenses/MIT
// This software uses Qt (http://qt.nokia.com)

#include "canvastest.h"
#include <QDebug>
#include <QtGui/QLabel>
#include <QtCore/QEvent>
#include <QtGui/QMouseEvent>
#include <QtGui/QApplication>

CanvasTest::CanvasTest(MetroApplication* metroApp, QWidget *parent)
    : QLabel(parent)
{
    if(!metroApp) {
        close();
        return;
    }

    this->metroApp = metroApp;
    setGeometry(100, 100, 300, 300);
}

void CanvasTest::resizeEvent(QResizeEvent*)
{
    metroApp->resize(size());
}

void CanvasTest::onRender()
{
    qApp->processEvents();
    metroApp->render();
    setPixmap(QPixmap::fromImage(metroApp->image()));
}

bool CanvasTest::event(QEvent *e)
{
    switch(e->type()) {
    case QEvent::MouseButtonPress:
    case QEvent::MouseMove:
    case QEvent::MouseButtonRelease:
        //e->accept();
        QApplication::sendEvent(metroApp, e);
        onRender();
        return true;
    default:
        return QLabel::event(e);
    }
}

CanvasTest::~CanvasTest()
{
}
